#!/bin/bash

DOCKER_NAME="qascript-logseer-api-test"

if [ -d {{ data_dir }}/logseer-qatest/log ];then
    mv {{ data_dir }}/logseer-qatest/log {{ data_dir }}/logseer-qatest/log-`date +%F-%H%M%S`
fi


if [ -d {{ data_dir }}/logseer-qatest/report ];then
    mv {{ data_dir }}/logseer-qatest/report  {{ data_dir }}/logseer-qatest/report-`date +%F-%H%M%S`
fi

if [ -d {{ data_dir }}/logseer-qatest/test-output ];then
    mv {{ data_dir }}/logseer-qatest/test-output  {{ data_dir }}/logseer-qatest/test-output-`date +%F-%H%M%S`
fi


ret=$(docker ps -a |grep "$DOCKER_NAME"|grep -v grep|wc -l)
if [ $ret -gt 0 ];then
    docker stop $DOCKER_NAME &>/dev/null
    docker rm $DOCKER_NAME
fi

# 获取dns的clusterip地址，在机器上测试时使用
# 轻舟名称: coredns
# rancher部署k8s是: kube-dns
CLUSTER_DNS_SVC_IP=$(kubectl -n kube-system get svc |grep dns|awk '{print $3}'|sed 's/ //g')

docker run --net host --dns $CLUSTER_DNS_SVC_IP --name $DOCKER_NAME \
-v {{ data_dir }}/logseer-qatest/conf:/conf \
-v {{ data_dir }}/logseer-qatest/testngxmls/testng.xml:/testng.xml \
-v {{ data_dir }}/logseer-qatest/log:/log \
-v {{ data_dir }}/logseer-qatest/report:/report \
-v {{ data_dir }}/logseer-qatest/test-output:/test-output \
-d {{ image_registry.addr }}/{{ image_registry.project }}/logseertest:v1.0.0-7b67d3cc
